import EventManager from "../Managers/EventManager";
import { EventTypes } from "../Managers/EventTypes";
import SDK from "./SDK";

export class TTSDK extends SDK {
    protected onEvents() {
        super.onEvents();
        EventManager.on(EventTypes.GameEvents.GameRun, this.onGameRun, this);
        EventManager.on(EventTypes.GameEvents.GameOver, this.onGameOver, this);
        //
        EventManager.on(EventTypes.SDKEvents.StartRecord, this.onStartRecord, this);
        EventManager.on(EventTypes.SDKEvents.PauseRecord, this.onPauseRecord, this);
        EventManager.on(EventTypes.SDKEvents.ResumeRecord, this.onResumeRecord, this);
        EventManager.on(EventTypes.SDKEvents.StopRecord, this.onStopRecord, this);
        EventManager.on(EventTypes.SDKEvents.ShareRecord, this.onShareRecord, this);
    }


    //#region -------------功能------
    //注册菜单分享事件
    protected onShareAppMessage() {
        window['tt'].onShareAppMessage(() => {
            return {
                title: '',
                imageUrl: '',
                // title: '这是要转发的小程序标题',
                // desc: '这是默认的转发文案，用户可以直接发送，也可以在发布器内修改',
                // path: '/pages/index/index?from=sharebuttonabc&otherkey=othervalue', // ?后面的参数会在转发页面打开时传入onLoad方法
                // imageUrl: 'https://e.com/e.png', // 支持本地或远程图片，默认是小程序 icon
                // templateId: '这是开发者后台设置的分享素材模板id',
                // success() {
                //     console.log('转发发布器已调起，并不意味着用户转发成功，微头条不提供这个时机的回调');
                // },
                // fail() {
                //     console.log('转发发布器调起失败');
                // }
            }

        });
    }
    //插屏
    protected showInterstitial() {
        console.log('TT 关闭插屏');
    }

    //#endregion

    //#region --------事件---------
    protected onGameRun() {
        this.onStartRecord();
    }

    protected onGameOver() {
        this.onStopRecord();
    }

    //--录屏
    protected onStartRecord() {
    }
    protected onPauseRecord() {
    }
    protected onResumeRecord() {
    }
    //停止录屏（头条）
    protected onStopRecord() {
    }
    //分享录屏（头条）
    protected onShareRecord(success: Function, fail: Function = null) {

    }

    //#endregion
}
/**录屏数据记录 */
class RecordVideoData {
    public startTime: number;
    public endTime: number;
    public gameShareCount: number;
    public dayShareCount: number;
    public constructor(data) {
        this.startTime = 0;
        this.endTime = 0;
        this.gameShareCount = 0;
        if (!!data) {
            this.dayShareCount = data.dayShareCount;
        } else {
            this.dayShareCount = 0;
        }
    }
    /**录屏开始 */
    public onStart() {
        this.startTime = Date.now();
        this.endTime = Date.now();
    }
    /**录屏结束 */
    public onEnd() {
        this.endTime = Date.now();
    }
    /**录屏时长，单位：秒 */
    public get totalTime() {
        return (this.endTime - this.startTime) * 0.001;
    }
    /**分享成功 */
    public onShare() {
        this.gameShareCount++;
        this.dayShareCount++;
    }
}